package com.scommunity.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scommunity.domain.Prop;
import com.scommunity.mapper.PropMapper;
import com.scommunity.service.IPropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PropServiceImpl extends ServiceImpl<PropMapper,Prop> implements IPropService{
    @Autowired
    PropMapper propMapper;

    @Override
    public PageInfo<Prop> all(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Prop> list = propMapper.selectList(null);
        PageInfo<Prop> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Prop add(Prop prop) {
        propMapper.insert(prop);
        return propMapper.selectOne(new QueryWrapper<Prop>().eq("prop_id",prop.getPropId())
                .eq("prop_num",prop.getPropNum()).eq("prop_name",prop.getPropName())
                .eq("fix_time",prop.getFixTime()).eq("fix_term",prop.getFixTerm())
                .eq("prop_status",prop.getPropStatus()));
    }

    @Override
    public void delete(Prop prop) {
        propMapper.deleteById(prop.getPropId());
    }

    @Override
    public void updateN(Prop prop) {
        propMapper.updateById(prop);
    }

    @Override
    public PageInfo<Prop> getPageByCondition(Prop prop, int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Prop> list = propMapper.getByCondition(prop);
        PageInfo<Prop> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
